<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.2.1.min.js"></script>
    <script>
        $(function () {
            $.post("/user/getInfo",null,function (userObj) {
                if(userObj.length == 0){
                    $("#loginSpan").html("<a href='login.html'>请先登录</a>")
                }else {
                    $("#loginSpan").html("欢迎光临，" + userObj.name)
                }

            });

            $.post("/primary/findAll",null,function (primaryList) {
                var str = "";
                for(var i=0;i<primaryList.length;i++){
                    var obj = primaryList[i];
                    str += `<tr><td>${obj.title}</td><td>${obj.user.name}</td><td>${obj.replyNum}</td>
                        <td>${obj.createDate}</td>
                        <td><a href="/html/showPrimary.html?primaryId=${obj.id}">查看详情</a></td></tr>`;
                }

                $("#data").html(str);
            });
        })

        function add() {
            $.post("/user/getInfo",null,function (userObj) {
                if (userObj.length == 0) {
                    alert("请先登录");
                }else {
                    location.href="add.html";
                }
            })
        }
    </script>
</head>
<body>
    <div>
        <span id="loginSpan"></span>
    </div>

    <table border="1" width="60%" cellspacing="0">
        <thead><tr><th>主题</th><th>作者</th><th>回帖数量</th><th>创建时间</th><th>操作</th></tr></thead>
        <tbody id="data"></tbody>
    </table>
    <a href="javascript:add()">发表主贴</a>
</body>
</html>